crc.htmlHTMLudog‚πùΔ¢πùΔ¢ÅÅ™t Monkeybread Realbasic plugin - Documentation - CRC

MBS Plugin Documentation

This is the documentation for the Realbasic Plugins from Monkeybreadsoftware.de. You find these plugins and the newest version of this document at http://www.monkeybreadsoftware.de/realbasic inside the plugins section.

This help was last updated on Freitag, 6. September 2002 and covers 2136 items: 126 classes, 2 controls and 583 global functions.

The list of the themes Global methods by category Global methods by name The list of the classes The list of the controls

CRC_32(s as String) as Integer

global method, CRC Do, 29. Aug 2002
Mac OS Classic: Works Mac OS Carbon: Works Windows: Works
Function: Calculates a 32bit Checksum about the provided string.
Example:
n=CRC_32("Hello World")
' n is now 1243066710
Notes:
See the text "About-CRC" for details about this Checksum things.
This function is also available as part of the memoryblock class.

About Checksums:

These functions calculate CRCs over a range of bytes in a MemoryBlock or in a String.

There's three versions of CRC calculation: One for 16 Bit, one for 32 Bit and one for 16 to 64 Bit wide checksums. If you are free to choose, I suggest that you use the 32 Bit version because of its accuracy and performance.

Some background on using checksums/CRCs:
Checksums, such as CRCs, are used to quickly verify that a chunk of data has not been modified somehow without your control. To use it, you'd calculate the checksum (CRC) of your data, then store that checksum value (which only needs 2 to 8 bytes of storage) somewhere. Later, when retrieving your data, you calculate its checksum again and compare its value with the previously stored value. If it does not match, the data got somehow corrupted. If it matches, that it is quite likely, although not 100% sure, that the data is still in its original state.

There are 3 different CRC algorithms available:

* CRC_CCITT...() as Integer
* CRC_32...() as Integer
* CRC_Dillon...(bitWidth as Integer, ...) as String

The CCITT version calculates a rather classic 16 bit CRC. Unless you need that CRC for legacy data, I recomment not to use it, but rather use the CRC_32 version.

CRC_32 is the most common used algorithm for 32 bit wide CRCs. Be aware there are theoretically many other ways to calculate a CRC 32, however.

The Dillon algorithm is a smart routine to calculate CRCs in any width between 16 and 64 bit. This one is only useful if you find that a 32 bit CRC is not sufficient for your needs. If you can live with a plain 32 bit CRC, you should prefer the CRC_32 routines, because they are faster than the Dillon code.

The result, since it can be up to 64 bit in size, cannot be returned in an Integer (they can only hold 32 bit). Instead, the result is returned as a 8 byte value, stored in a 8 byte long string. To get the value of that string, you can copy the string into a MemoryBlock, and then access the parts opf the 8 byte long value there. The demo project shows how to accomplish this.

The CRC code was developed and published by Matthew Dillon, <dillon@backplane.com>. Here's his web page with more information about it: <http://www.backplane.com/diablo/crc64.html>

Summary of all methods provided for CRC:

* CRC_CCITT(s as String) as Integer
* CRC_32(s as String) as Integer
* CRC_Dillon(bitWidth as Integer, s as String) as String

* MemoryBlock.CRC_CCITT(offset as Integer, numBytes as Integer) as Integer
* MemoryBlock.CRC_32(offset as Integer, numBytes as Integer) as Integer
* MemoryBlock.CRC_Dillon(bitWidth as Integer, offset as Integer, numBytes as Integer) as String

CRC_CCITT(s as String) as Integer

global method, CRC Do, 29. Aug 2002
Mac OS Classic: Works Mac OS Carbon: Works Windows: Works
Function: Calculates a 16bit Checksum about the provided string.
Example:
n=CRC_CCITT("Hello World")
' n is now 39210
Notes:
See the text "About-CRC" for details about this Checksum things.
This function is also available as part of the memoryblock class.

See the CRC_32 for more details on Checksums.

CRC_Dillon(bitWidth as Integer, s as String) as String

global method, CRC Do, 29. Aug 2002
Mac OS Classic: Works Mac OS Carbon: Works Windows: Works
Function: Calculates a 16 to 64bit Checksum about the provided string.
Example:
s=CRC_Dillon(64,"Hello World")
' s has now the 64bit checksum inside an 8 byte binary string
Notes:
See the text "About-CRC" for details about this Checksum things.
This function is also available as part of the memoryblock class.

See the CRC_32 for more details on Checksums.

Contact

Written 2002 by Christian Schmitz. Feel free to ask or report mistakes to realbasic@macsw.de.
Thanks.

This resource fork intentionally left blank ˇˇ